  var map = null; 
	var mgr = null;
	
	var dirPanel1, dirPanel2, dirPanel3;
	var wheelZooming = false;
	var mouseLatLng;

	var mgrOptions = { borderPadding: 50, maxZoom: 15};
	
	function setIcons(vehicles) {
		var vIcon = new GIcon();
		vIcon.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";
		vIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		vIcon.iconSize = new GSize(12, 20);
		vIcon.shadowSize = new GSize(22, 20);
		vIcon.iconAnchor = new GPoint(6, 20);
		vIcon.infoWindowAnchor = new GPoint(5, 1);
		vIconStyle = { icon:vIcon };
	}
	
	function setupMap(vehicles) {
//	  if (map != null) {
          if (GBrowserIsCompatible()) {
    	  
            map = new GMap2(document.getElementById("map_canvas"));
            map.addControl(new GLargeMapControl());
		    map.setCenter(new GLatLng(41.9, 12.483333), 5);		
         
		    container = document.getElementById("map_canvas");
		    GEvent.addDomListener(container, "DOMMouseScroll", wheelZoom);
		    GEvent.addDomListener(container, "mousewheel", wheelZoom); 
    		
		    setIcons(vehicles);
		    // metti su mappa i marker relativi a posizione veicoli
            setupMarkers(vehicles);
	      }
//	  }
    }
	

	function createMarker(lat,lon,iType,number, dati) { 
 	  var marker= new GMarker(new GLatLng(lat,lon), iType);
	  GEvent.addListener(marker, "click", 
	  function() {   
	    var myHtml = "Veicolo: " + dati[1] + "</br>" +
	                 "Targa: " + dati[2] + "</br>"
	                 //"Tipo Mezzo: " + dati[3] + "</br>" + 
					 //"Azienda: " + dati[4] + "</br>" + 
					 //"Deposito: "+ dati[5] + "</br>" +
		if (dati[11] != "" && dati[11] != "0") 
			myHtml = myHtml + "Inizio missione: "+ dati[11]+" </br>" +   
						     "Fine missione: "+ dati[12]+" </br> "
		if (dati[8] == "" || dati[8] == "0") 
			myHtml = myHtml + "<b> Posizione attuale: "+ dati[5] +" (Deposito) </b>";   
		else 
			myHtml = myHtml +  "<b> Posizione attuale: </br>Lat: "+dati[8].substring(0,6)+" Long: "+dati[9].substring(0,6) + "</br>" + 
					" Aggiornato al "+ dati[10]+"</b>"

	    map.openInfoWindowHtml(new GLatLng(lat,lon), myHtml);  
	  });  
	  return marker;
    }
	
	// inserisce i marker dei veicoli sulla Mappa
	function setupMarkers(vehicles) {
		map.clearOverlays();
		for (i=0; i<vehicles[0].length; i++)
		{
			var dati = new Array();
			for (j=0; j<vehicles.length; j++)
			{
				dati[j] = vehicles[j][i];
			}
			
			if (dati[8] == "" || dati[8] == "0")
			{
				eval("var gm"+ dati[0] +"= createMarker("+parseFloat(dati[6].replace(',','.'))+","+parseFloat(dati[7].replace(',','.'))+",vIconStyle,"+dati[0]+", dati); ")
				eval("map.addOverlay(gm"+ dati[0] +");")
			}
			else
			{
				eval("var gm"+ dati[0] +"= createMarker("+parseFloat(dati[8].replace(',','.'))+","+parseFloat(dati[9].replace(',','.'))+",vIconStyle,"+dati[0]+", dati); ")
				eval("map.addOverlay(gm"+ dati[0] +");")
			}
		}
	}
	
	function setCenter(ddmTipoVeicolo)
	{
//	if (map != null) {
	        var center;
		    center = parseInt(ddmTipoVeicolo.value);
		    var dato = new Array();
		    if (ddmTipoVeicolo.value == -1)
			    map.setCenter(new GLatLng(41.9, 12.483333), 5);
		    else
		    {
			    dato = ddmTipoVeicolo.value.split(";")
			    eval("map.setCenter(new GLatLng("+parseFloat(dato[0].replace(',','.'))+","+parseFloat(dato[1].replace(',','.'))+"), 8);")
		    }
//		}
	}
	
	function wheelZoom(event)
	{
		if (wheelZooming) {
			return;
		}
	
		wheelZooming = true;

		if (event.cancelable) {
			event.preventDefault();
		}
		map.closeInfoWindow(); 
		if((event.detail || -event.wheelDelta) < 0) {
			window.setTimeout(function(){
				map.zoomIn(mouseLatLng,true,true);
				wheelZooming = false;
			},200);
		} 
		else {
			window.setTimeout(function(){
				map.zoomOut(mouseLatLng,true);
				wheelZooming = false;
			},200);
		}
		return false; 
	}